<template>
	<div>
		<div class="h2">作业列表</div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="名称">
							<a-input autocomplete="off" class="field-right" placeholder="请输入名称搜索"
								v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<!-- <a-col :span="8">
						<a-form-item label="部门">
							<a-select :allowClear="true" v-decorator="['departCode']" placeholder="全部" optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in DepartCodeList" :key="index" :value="item.Code">{{ item.Name }}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col> -->
					<!-- <a-col :span="8" style="margin-top:4px;">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button :style="{ marginLeft: '8px' }" @click="handleReset" class="btn2">重置</a-button>
					</a-col> -->
				</a-row>
			</a-form>
		</div>
		<a-button-group size="default" class="option">
			<a-button type="primary" @click="handleSearch">搜索</a-button>
			<a-button @click="handleReset">重置</a-button>
			<a-button type="primary" @click="addList">新增</a-button>
			<!-- 
			<a-button type="primary" @click="exportList()">导出</a-button> -->
		</a-button-group>
		<div>
			<el-table :data="data" default-expand-all v-loading="loading"  :max-height="tableHeight" highlight-current-row
				style="width: 100%;">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="Title" label="名称" min-width="150"></el-table-column>
				
				<el-table-column prop="Name" label="答题方式" min-width="240" align="center">
					<template slot-scope="scope">
						<div style="text-align: center;">
							
							{{ scope.row.Type=='1'?'多行文本在线输入':scope.row.Type=='2'?'上传附件':'' }}
						</div>
				
					</template>
				</el-table-column>
				
				<el-table-column label="操作" width="180" fixed="right">
					<template slot-scope="scope">
						<div class="user-btn">
							<span class="modify" @click="modifyList(scope.row, 'modify')">修改</span>
							<span class="delete" @click="deleteList(scope.row)">删除</span>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		<add :text="text" :DepartCodeList="DepartCodeList" :ClassList="ClassList" v-show="addIf" @closeFun="closeFun">
		</add>
		<addItem :text="textItem" v-show="addIfItem" @closeFun="closeFun">
		</addItem>
	</div>
</template>

<script>
	import Cache from '@/utils/cache';
	import add from './add';
	import addItem from './addItem';
	import Func from '@/utils/func';
	import moment from 'moment';
	import {
		ManageActivityJobDoGetPageList,
		ManageHeadMasterEvaluationSubjectDoDelete,
		ManageHeadMasterEvaluationSubjectItemDoDelete,
		ManageHeadMasterEvaluationSubjectItemDoSort,
		GetDepartList,
		GetClassList,
		DoUnbundTeacher,
		ManageActivityJobDoDelete
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			add,
			addItem
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				addIfItem: false,
				text: {},
				textItem: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				gradeYear: null,
				yearPickShow: false,
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				ClassList: [],
				DepartCodeList: [],
				requestUrl: this.global.requestUrl,
				token: Cache.get('token')
			};
		},
		computed: {},
		created() {
			this.getList();
			// this.getOtherList();
		},
		mounted() {},
		methods: {
			moment,
			exportList() {
				this.form.validateFields((error, values) => {
					let data = {};
					data.key = values.key;
					data.departCode = values.departCode;
					let hrefUrl = this.requestUrl + 'Manage/Teacher/DoExport?userToken=' + encodeURIComponent(this
						.token);
					let hrefStr = '';
					for (let key in data) {
						if (data[key]) {
							hrefStr += key + '=' + data[key] + '&';
						}
					}
					window.open(hrefUrl + '&' + hrefStr, '_blank');
				});
			},
			handleOpenChange(status) {
				this.yearPickShow = status;
			},
			handlePanelChange(value, mode) {
				this.gradeYear = moment(value).format('YYYY');
				this.yearPickShow = false;
			},
			yearChange(date, dateString) {
				if (!date) {
					this.gradeYear = null;
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					if (this.gradeYear) {
						this.values.grade = this.gradeYear;
					}
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.gradeYear = null;
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.activityID = this.$route.query.ID;
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await ManageActivityJobDoGetPageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				let res = await GetClassList();
				this.ClassList = res.data.data;
				let res1 = await GetDepartList();
				this.DepartCodeList = res1.data.data;
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			open(text) {
				this.textItem = {
					HeadMasterEvaluationSubjectID: text.ID,
					time: new Date(),
					type:'add'
				};
				this.addIfItem = !this.addIfItem;

			},
			open2(text){
				// console.log(text);
				text = Object.assign(text, {
					time: new Date(),
					type:'edit'
				});
				this.addIfItem = !this.addIfItem;
				this.textItem = text;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			deletemember(text){
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该选项吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await ManageHeadMasterEvaluationSubjectItemDoDelete(data);
						console.log(res);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			deleteList(text, type) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定要删除该数据吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await ManageActivityJobDoDelete(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			seeList(text, name) {
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						Name: text.Name,
						UserNo: text.UserNo
					}
				});
			},
			closeFun() {
				this.addIf = false;
				this.addIfItem = false;
				this.getList();
			},
			async sortList(text,type){
				// 1=向上 2=向下
				let data={}
				data.id = text.ID
				data.type = type
				let res = await ManageHeadMasterEvaluationSubjectItemDoSort(data);
				if(res.data.code==0){
					this.getList();
					this.$message.success(res.data.msg)
				}else{
					this.$message.error(res.data.msg)
				}
			},
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;
	}

	/deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.ant-calendar-picker {
		width: 100%;
	}
</style>
